<?
class PollBO extends BusinessObject{

  /* private function using in constructors */ 
  function setAttributes(){
	$this->fields	= array(
		'id'			=>	'poll_ID',
		'name'		=>	'poll_Name', // short name
		'question'	=>	'poll_Question',
		'descr'		=>	'poll_Descr',
		'date_from'	=>	'poll_DateFrom',
		'date_to'		=>	'poll_DateTo',
		'visible'		=>	'poll_Visible',
		);

//    $st = new SubPollBO();
//    $this->relations = array("{$st->tableName}" =>"{$st->tableName}.{$st->fields[poll_id]} = {$this->tableName}.{$this->fields[id]}");

    BusinessObject::setAttributes();
  }
  /* constructor */
  function PollBO(){
    /** super(tableName) */
    BusinessObject::BusinessObject("poll");
    $this->setAttributes();
  }
  
    /*  Save  */
  function Save($pollID){
    if(is_numeric($pollID) && $pollID<>0){
      $this->id = $pollID;
      $this->Update("{$this->fields[id]} = '$pollID'");  
    } else{
      $this->Insert();
      $this->id = $this->getInsertID();
    }
  }

  // function 'get_poll_as_html' return the tag(s) OPTION with names and ids
  function get_poll_as_html($selected_pollID, $visible=1){
    $reg = new PollBO();
    $ret = "";
	$reg->visible = $visible;
    $reg->Load(0,0,array($reg->fields['name']=>0));
    while ($reg->Next()) {
      $ret.= "<option value='{$reg->id}' ".(($selected_pollID==$reg->id)?"selected":"").">".$reg->name."</option>";
    }
    return $ret;
  }

}
?>